use crate::dao;
use crate::models::models::components::v2ray::server::ComponentV2rayServer;
use crate::runtime::error::MagicBoxError;
use crate::runtime::response::{Code, MagicBoxResponse};
use crate::runtime::result::MagicBoxResult;

#[tauri::command(rename_all = "snake_case")]
pub(crate) async fn invoke_component_v2ray_remove_server(server: ComponentV2rayServer) -> MagicBoxResult<MagicBoxResponse<()>> {
    if server.used {
        return Err(MagicBoxError::new(Code::ParameterError, "当前服务器配置正在使用中，无法删除"));
    }

    dao::components::v2ray::server::remove_server_config(server.uuid.clone())?;

    Ok(MagicBoxResponse::new_empty_success())
}